var TAN_CIG={HOST_URL:"http://wx.tan66.com",HOST_PC_URL:"http://www.tan66.com"}
function doRequest(a, b, c, e, d) {
	try {
		$.ajax({
			url: a,
			async: c,
			type: "post",
			dataType: "json",
			data: b,
			timeout: 6E4,
			success: function(a) {
				1 == a.reqStatus ? e(a) : d(a)
			},
			error: function(a, b, c) {}
		})
	} catch(f) {}
}
function doGetRequest(a,b,c,e,d){try{$.ajax({url:a,async:c,type:"get",dataType:"json",data:b,timeout:6E4,success:function(a){1==a.reqStatus?e(a):d(a)},error:function(a,b,c){}})}catch(f){}}
String.Format=function(){if(0==arguments.length)return null;for(var a=arguments[0],b=1;b<arguments.length;b++)a=a.replace(new RegExp("\\{"+(b-1)+"\\}","gm"),arguments[b]);return a};
//使active能使用 仅为A标签
function active(a){
	for(var i = 0; i < a.length; i++){
		a[i].addEventListener('touchstart',function(){},false);
	}
};
$(function(){
	active($('a'));
	active($('button'));
	active($('input'));
});

//限制字符
function txtLimit(object,textLeng) {
     if(typeof arguments[0]=='object'){
         for (i = 0; i < arguments[0].length; i++) {
             var str = arguments[0][i].innerHTML;
             if (str.length > textLeng) {
                 arguments[0][i].innerHTML = str.substring(0, textLeng) + "...";
             }
         }
     }else{
         return object.substring(0, textLeng) + "...";
     }
};
//全局弹窗
$('.public-btn').on('click',function(){
	$('.public').fadeIn();
	setTimeout(aaa,2000);
	function aaa(){
		$('.public').fadeOut()
	};
});

//登录弹窗显示
$(window).scroll(function(){
    var _top = $(window).scrollTop();
    if( _top >= 50 ){
        $(".index-popup").stop(true).fadeIn();
	}if( _top < 50 ){
    	$(".index-popup").stop(true).fadeOut();
    };
});
        
function _is_login(){
    if(is_login.isline==0){
        layer.open({
            title:"您还未登录哦",content: '还能不能愉快的交朋友了？',btn: ['现在登录', '以后再说'],yes: function(index){
                layer.close(index);
                window.location.href="/account/login.html?redirectUrl="+encodeURIComponent(window.location.href);
            }
        });
        return false;
    }else{
        return true;
    }
}
function check_str_len(str){
    var total_len,ch_len,en_len;
    if(str == "") return 0;
    total_len=str.length,en_len=(str.replace(/[\u4E00-\u9FA5]/g,"")).length,ch_len=total_len-en_len,en_len=parseInt(en_len/2);
    return ch_len+en_len;
}
function Hashtable() {
    this._hash = new Object();
    this.put = function(key, value) {
        if (typeof (key) != "undefined") {
            if (this.containsKey(key) == false) {
                this._hash[key] = typeof (value) == "undefined" ? null : value;
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    this.remove = function(key) { delete this._hash[key]; }
    this.size = function() { var i = 0; for (var k in this._hash) { i++; } return i; }
    this.get = function(key) { return this._hash[key]; }
    this.containsKey = function(key) { return typeof (this._hash[key]) != "undefined"; }
    this.clear = function() { for (var k in this._hash) { delete this._hash[k]; } }
}
var emotions = new Array();
var categorys = new Array();// 分组
var uSinaEmotionsHt = new Hashtable();
$(function(){
    txtLimit($(".textnum8"),8);
    txtLimit($(".textnum10"),10);
    txtLimit($(".textnum13"),13);
    txtLimit($(".textnum15"),15);
    txtLimit($(".textnum20"),20);
    txtLimit($(".textnum25"),25);
    txtLimit($(".textnum30"),30);
    txtLimit($(".textnum35"),35);
    txtLimit($(".textnum50"),50);
    txtLimit($(".textnum100"),100);
    txtLimit($(".textnum110"),110);
    txtLimit($(".textnum170"),170);
    
    $.fn.banner_round = function(){
        var _self = $(this),
            _next = _self.find("#btn-next"),
            _prev = _self.find("#btn-prev"),
            _a = _self.siblings(".flicking_con").find("a"),
            _visual = _self.parent(".main_visual");
        $dragBln = false;
        _self.touchSlider({
            flexible : true,
            speed : 200,
            btn_prev : _prev,
            btn_next : _next,
            paging : _self.siblings(".flicking_con").find("a"),
            counter : function (e){
                _a.removeClass("current").eq(e.current-1).addClass("current");
            }
        });
        _self.bind("mousedown", function() {
            $dragBln = false;
        }).bind("dragstart", function() {
            $dragBln = true;
        });
        timer = setInterval(function(){
            _next.click();
        }, 4000);
        _visual.hover(function(){
                clearInterval(timer);
        },function(){
            timer = setInterval(function(){
                _next.click();
            },4000);
        });
        _self.bind("touchstart",function(){
            clearInterval(timer);
        }).bind("touchend", function(){
            timer = setInterval(function(){
                _next.click();
            }, 4000);
        });
    }
    $.extend({
        tipsBox: function (options) {
            options = $.extend({
                obj: null,  //jq对象，要在那个html标签上显示
                str: "+1",  //字符串，要显示的内容;也可以传一段html，如: "<b style='font-family:Microsoft YaHei;'>+1</b>"
                startSize: "8px",  //动画开始的文字大小
                endSize: "15px",    //动画结束的文字大小
                interval: 600,  //动画时间间隔
                moveTop:20,
                moveLeft:0,
                color: "red",    //文字颜色
                callback: function () { }    //回调函数
            }, options);
            $("body").append("<span class='num_ani'>" + options.str + "</span>");
            var box = $(".num_ani");
            var left = options.obj.offset().left + options.obj.width() / 2;
            var top = options.obj.offset().top - options.obj.height() / 2;
            box.css({
                "position": "absolute",
                "left": (left+options.moveLeft) + "px",
                "top": (top+options.moveTop)+ "px",
                "z-index": 9999,
                "font-size": options.startSize,
                "line-height": options.endSize,
                "color": options.color
            });
            box.animate({
                "font-size": options.endSize,
                "opacity": "0",
                "top": top - parseInt(options.endSize) + "px"
            }, options.interval, function () {
                box.remove();
                options.callback();
            });
        }
    });
    if(typeof(is_load_face) != "undefined"){
        var data = emotions_json.data;
        for ( var i in data) {
            if (data[i].category == '') {
                    data[i].category = '默认';
            }
            if (emotions[data[i].category] == undefined) {
                    emotions[data[i].category] = new Array();
                    categorys.push(data[i].category);
            }
            emotions[data[i].category].push( {
                    name : data[i].phrase,
                    icon : data[i].icon
            });
            uSinaEmotionsHt.put(data[i].phrase, data[i].icon);
        }
    }
      $.fn.font_scroll = function(options){
            var d = {time: 3000,s: 'fontColor',num: 1}
            var o = $.extend(d,options);


            this.children('ul').addClass('line');
            var _con = $('.line').eq(0);
            var _conH = _con.height(); //滚动总高度
            var _conChildH = _con.children().eq(0).height();//一次滚动高度
            var _temp = _conChildH;  //临时变量
            var _time = d.time;  //滚动间隔
            var _s = d.s;  //滚动间隔
            _con.clone().insertAfter(_con);//初始化克隆
            //样式控制
            var num = d.num;
            var _p = this.find('li');
            var allNum = _p.length;

            _p.eq(num).addClass(_s);


            var timeID = setInterval(Up,_time);
                    this.hover(function(){clearInterval(timeID)},function(){timeID = setInterval(Up,_time);});

            function Up(){
                _con.animate({marginTop: '-'+_conChildH});
                //样式控制
                _p.removeClass(_s);
                num += 1;
                _p.eq(num).addClass(_s);

                if(_conH == _conChildH){
                    _con.animate({marginTop: '-'+_conChildH},"normal",over);
                } else {
                    _conChildH += _temp;
                }
            }
            function over(){
                _con.attr("style",'margin-top:0');
                _conChildH = _temp;
                num = 1;
                _p.removeClass(_s);
                _p.eq(num).addClass(_s);
            }
    }
    //举报弹窗
    $.fn.report = function(){
        var _self = $(this),
            _report_pop = $(".report-pop"),
            _rel = _self.attr("data-rel"),
            _li = _report_pop.find("li"),
            _close = _report_pop.find(".report-close"),
            _content = _report_pop.find(".report-content"),
            _btn = _report_pop.find("._report_btn");
        var S = function(){
            _report_pop.stop().fadeIn();
            _content.animate({'top':'50%'},300);
        }
        var F = function(){//移除举报框
            _report_pop.stop().fadeOut();
            _content.animate({'top':'30%'},300);
        }
        _report_pop.one("click",function(){
            return F();//阴影处移除
        });
        _li.on("click",function(){
            return $(this).addClass('active').siblings().removeClass('active');
        });
        _content.on("click",function(e){
            e.stopPropagation();
        });
        _close.on("click",function(){
            return F();
        });
        _btn.unbind("click").bind("click",function(){
            var _des=$("#report_description").val(),_type=_report_pop.find("li.active").find("input").val();
            if(_type === "" || _type == undefined){$.mvalidateTip("请选择举报原因");return;}
            doRequest("/ajax/ajax_report",{des:_des,type:_type,rel:_rel},false,function(data){
                return F(),$.mvalidateTip(data.errorMsg);
            },function(data){
                return $.mvalidateTip(data.errorMsg);
            });
        });
        return S();
    }
    
    $.fn.gallery_img = function(){
        // 读取尺寸大小
        var imgReady = (function () {
            var list = [], intervalId = null,
            // 用来执行队列
            tick = function () {
                    var i = 0;
                    for (; i < list.length; i++) {
                            list[i].end ? list.splice(i--, 1) : list[i]();
                    };
                    !list.length && stop();
            },
            // 停止所有定时器队列
            stop = function () {
                    clearInterval(intervalId);
                    intervalId = null;
            };
            return function (url, ready, load, error) {
                var onready, width, height, newWidth, newHeight,img = new Image();
                img.src = url;
                // 如果图片被缓存，则直接返回缓存数据
                if (img.complete) {
                    ready.call(img);
                    load && load.call(img);
                    return;
                };
                width = img.width;
                height = img.height;
                img.onerror = function () {
                    error && error.call(img);
                    onready.end = true;
                    img = img.onload = img.onerror = null;
                };
                // 图片尺寸就绪
                onready = function () {
                    newWidth = img.width;
                    newHeight = img.height;
                    if (newWidth !== width || newHeight !== height || newWidth * newHeight > 1024){
                        // 如果图片已经在其他地方加载可使用面积检测
                        ready.call(img);
                        onready.end = true;
                    };
                };
                onready();
                // 完全加载完毕的事件
                img.onload = function () {
                    // onload在定时器时间差范围内可能比onready快
                    // 这里进行检查并保证onready优先执行
                    !onready.end && onready();
                    load && load.call(img);
                    // IE gif动画会循环执行onload，置空onload即可
                    img = img.onload = img.onerror = null;
                };
                // 加入队列中定期执行
                if (!onready.end) {
                    list.push(onready);
                    // 无论何时只允许出现一个定时器，减少浏览器性能损耗
                    if (intervalId === null) intervalId = setInterval(tick, 40);
                };
            };
        })();
        $(this).each(function(index, el) {//自定义——将其他图片做成这种形式
            var self = $(this);
            imgReady($(this).attr("src"), function () {
                $(self).wrap('<a href="'+$(self).attr("src")+'" data-size="'+this.width+"x"+this.height+'" data-med="'+$(self).attr("src")+'" data-med-size="'+this.width+"x"+this.height+'">');
            });
        });
        initPhotoSwipeFromDOM('.gallery');
    }
});
//手机浏览器信息
var brower_info = function(){
    var ua = navigator.userAgent;
    var brower = {
        is_phone : function(){//是否是手机终端
            return /Android|webOS|iPhone|iPod|BlackBerry/i.test(ua) ? true : false;
        },
        is_weixin : function(){//是否是微信
            return ua.toLowerCase().match(/MicroMessenger/i)=="micromessenger" ? true : false;
        },
        is_android : function(){//是否是安卓终端
            return /android/.test(ua.toLowerCase()) ? true : false;
        },
        is_iPhone : function(){//是否是苹果终端
            return /iphone|ipad|ipod/.test(ua.toLowerCase()) ? true : false;
        },
        is_ucBrower : function(){//是否是uc浏览器
            return ua.indexOf('UCBrowser') > -1 ? true : false;
        },
        is_qqBrower : function(){//是否是qq浏览器
            return ua.indexOf('QQBrowser') > -1 ? true : false;
        }
    };
    return brower;
}

//截取字符串 包含中文处理 
//(串,长度,增加...) 
function subString(str, len, hasDot) 
{ 
    var newLength = 0; 
    var newStr = ""; 
    var chineseRegex = /[^\x00-\xff]/g; 
    var singleChar = ""; 
    var strLength = str.replace(chineseRegex,"**").length; 
    for(var i = 0;i < strLength;i++) 
    { 
        singleChar = str.charAt(i).toString(); 
        if(singleChar.match(chineseRegex) != null) 
        { 
            newLength += 2; 
        }     
        else 
        { 
            newLength++; 
        } 
        if(newLength > len) 
        { 
            break; 
        } 
        newStr += singleChar; 
    } 
     
    if(hasDot && strLength > len) 
    { 
        newStr += "..."; 
    } 
    return newStr; 
} 